﻿
function SH_SelectOne(obj) {

    if (obj.checked == false) {
        document.getElementById('chkall').checked = obj.chcked;
    }
}

var scorebar = 0;
var InFloat = '';
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var is_mac = userAgent.indexOf('mac') != -1;

var charset = 'utf-8';

var jsmenu = new Array();
var ctrlobjclassName;
jsmenu['active'] = new Array();
jsmenu['timer'] = new Array();
jsmenu['iframe'] = new Array();

//判定dom类型是否定义
function isUndefined(variable) {
    return typeof variable == 'undefined' ? true : false;
}

//表单提交
function formSubmit(num, actionUrl, params) {
    var form = document.forms[num];
    form.params.value = params;
    form.action = actionUrl;
    form.submit();
}

//checkbox全选特效
function CheckAll(form, ckname) {
    var len = arguments.length
    for (var i = 0; i < form.elements.length; i++) {
        var e = form.elements[i];
        if (len == 2) {
            if (e.type == "checkbox" && e.name == ckname && e.name != 'deleteMode') {
                e.checked = form.chkall.checked;
            }
        }
        else {
            if (e.type == "checkbox" && e.name !="chkall" && e.name != 'deleteMode') {
                e.checked = form.chkall.checked;
            }
        }
    }
}
//指定name的check的值
function checkedlist(chkname) {
    var ids = jQuery("input:checked[name='"+chkname+"']");
    var prolist = Array();
    jQuery(ids).each(function() {
        prolist.push(jQuery(this).val());
    });
    return prolist.join(',');
}

//过滤符号
function checksign(str) {
    return str.replace('\'', '‘').replace('"', '“');
}





//隐藏指定元素位置下方的"下拉列表框",该函数主题解决ie6以前(包括ie6)的下拉列表框遮挡显示层的问题
function HideOverSels(objID) {
    var sels = document.getElementsByTagName('select');

    for (var i = 0; i < sels.length; i++) {
        if (Obj1OverObj2(document.getElementById(objID), sels[i])) {

            sels[i].style.visibility = 'hidden';
        }
        else {
            sels[i].style.visibility = 'visible';
        }
    }
}

//---------------------------------------------------AjaxHelper------------------------------------------------

var AjaxProxyUrl = new String("../ajax.aspx");

var AjaxHelper =
{
    Updater: function(ajaxTemplate, output, params, onComplete) {
        if (typeof output == 'string') {
            output = $(output);
        }

        var FormatContent = function(str) {
            var content = new String(str);
            var prefix = new String("<!--AjaxContent-->");
            content = content.substring(content.indexOf(prefix, 0) + prefix.length, content.length - 9);
            return content;
        }

        this.result = "1";
        var myrequest = new Ajax.Request(AjaxProxyUrl,
		{ onComplete: function(transport) {
		    if (output != null)
		    { output.innerHTML = FormatContent(transport.responseText); }
		    if (onComplete != null)
		    { onComplete(FormatContent(transport.responseText)) }

		    if ($("loading_mask") != undefined && $("loading") != undefined) {
		        $("loading_mask").style.display = "none";
		        $("loading").style.display = "none";
		    }
		}, parameters: params + '&AjaxTemplate=' + ajaxTemplate
		});

        var requeststate = myrequest.transport.readyState;
        if (requeststate != 4) {
            if ($("loading_mask") != undefined && $("loading") != undefined) {
                $("loading_mask").style.display = "block";
                $("loading").style.display = "block";
            }
        }

        return this.result;
    },


    SerializeForm: function(form) {
        return Form.serialize(form);
    }

}

function loading() {
    var body = document.getElementsByTagName("body")[0];

    var bodySize = [];
    bodySize[0] = (document.documentElement.scrollWidth > document.documentElement.clientWidth) ? document.documentElement.scrollWidth : document.documentElement.clientWidth; //如果滚动条的宽度大于页面的宽度，取得滚动条的宽度，否则取页面宽度
    bodySize[1] = (document.documentElement.scrollHeight > document.documentElement.clientHeight) ? document.documentElement.scrollHeight : document.documentElement.clientHeight; //如果滚动条的高度大于页面的高度，取得滚动条的高度，否则取高度
    var div = document.createElement("div");
    div.style.position = "absolute";
    div.style.top = "50%";
    div.style.left = "50%";
    div.style.margin = "-50px 0 0 -100px";
    div.style.padding = "15px";
    div.style.border = "0px solid #B2D0F7";
    div.style.color = "#003366";
    div.style.font = "bold 14px verdana,tahoma,helvetica";
    div.style.zIndex = '10002';
    div.style.textAlign = "center";
    div.innerHTML = "<img src='../images/loading.gif'/>";
    div.id = "loading";
    body.appendChild(div);
    div.style.display = "none";

    var divmask = document.createElement('div');
    divmask.style.position = 'absolute';
    divmask.style.width = bodySize[0] + "px";
    divmask.style.height = bodySize[1] + "px";
    divmask.style.top = "0px";
    divmask.style.left = "0px";
    divmask.style.zIndex = '10001';
    divmask.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
    divmask.style.opacity = 0.9;
    divmask.style.background = "#ffffff";
    divmask.id = "loading_mask";
    body.appendChild(divmask);
    divmask.style.display = "none";
}

//等待页面
function Msg_show(msgInfo, pageErr, skipurl) {

    msg_loading(msgInfo, pageErr);
    if (scorebar == 0) {
        $("loading_masks").style.display = "block";
        $("loading_success").style.display = "block";
    } else {
        $("loading_masks").style.display = "none";
        $("loading_success").style.display = "none";
    }

    if (skipurl != "") {
        setTimeout("window.location.href = '" + skipurl + "';", 3000);
    } else {
        if (scorebar == 0) {
            setTimeout("Msg_show('" + msgInfo + "','" + pageErr + "','" + skipurl + "');scorebar = scorebar + 1;", 3000);
        }
    }
}

//消息弹出
function msg_loading(msgInfo, pageErr) {

    var body = document.getElementsByTagName("body")[0];
    var bodySize = [];
    bodySize[0] = (document.documentElement.scrollWidth > document.documentElement.clientWidth) ? document.documentElement.scrollWidth : document.documentElement.clientWidth; //如果滚动条的宽度大于页面的宽度，取得滚动条的宽度，否则取页面宽度
    bodySize[1] = (document.documentElement.scrollHeight > document.documentElement.clientHeight) ? document.documentElement.scrollHeight : document.documentElement.clientHeight; //如果滚动条的高度大于页面的高度，取得滚动条的高度，否则取高度
    var divmask = document.createElement('div');
    divmask.style.position = 'absolute';
    divmask.style.width = bodySize[0] + "px";
    divmask.style.height = bodySize[1] + "px";
    divmask.style.top = "0px";
    divmask.style.left = "0px";
    divmask.style.zIndex = '10000';
    divmask.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
    divmask.style.opacity = 0.9;
    divmask.style.background = "#ffffff";
    divmask.id = "loading_masks";
    body.appendChild(divmask);
    divmask.style.display = "none";

    var div = document.createElement("div");
    div.style.position = "absolute";
    div.style.top = "50%";
    div.style.left = "50%";
    div.style.height = "120px";
    div.style.width = "284px";
    div.style.margin = "-80px 0 0 -150px";
    div.style.zIndex = '10002';
    div.id = "loading_success";    

    var MsgTitle = "操作提示";
    if (pageErr > 0) {
        MsgTitle = "错误提示 出现 " + pageErr + "条错误";
    }

    div.innerHTML = "\r\n<div id=\"Layer2\" style=\"position:absolute;z-index:10002;width:270px;height:90px;background-color: #FFFFFF;border:solid #000000 1px;font-size:14px;\">\r\n"
                    + "<div id=\"Layer4\" style=\"height:26px;background:#f1f1f1;line-height:26px;padding:0px 3px 0px 3px;font-weight:bolder;\">操作提示</div>\r\n"
                    + "<div id=\"Layer5\" style=\"height:64px;line-height:150%;padding:0px 3px 0px 3px;\" align=\"center\"><BR /><table><tr><td valign=top>" + msgInfo + "<BR /></td></tr></table><BR /></div>\r\n"
                    + "</div>\r\n"
                    + "<div id=\"Layer3\" style=\"position:absolute;width:270px;height:90px;z-index:10001;left:4px;top:5px;background-color: #E8E8E8;\"></div>\r\n"
                    + "</div>\r\n";
    body.appendChild(div);
    div.style.display = "none";

}

//-------------------------------------------------------------浮动展示--------------------------------------------------------------------

function doane(event) {
    e = event ? event : window.event;
    if (is_ie) {
        e.returnValue = false;
        e.cancelBubble = true;
    } else if (e) {
        e.stopPropagation();
        e.preventDefault();
    }
}

function initCtrl(ctrlobj, click, duration, timeout, layer) {
    if (ctrlobj && !ctrlobj.initialized) {
        ctrlobj.initialized = true;
        ctrlobj.unselectable = true;

        ctrlobj.outfunc = typeof ctrlobj.onmouseout == 'function' ? ctrlobj.onmouseout : null;
        ctrlobj.onmouseout = function() {
            if (this.outfunc) this.outfunc();
            if (duration < 3 && !jsmenu['timer'][ctrlobj.id]) jsmenu['timer'][ctrlobj.id] = setTimeout('hideMenu(' + layer + ')', timeout);
        }

        ctrlobj.overfunc = typeof ctrlobj.onmouseover == 'function' ? ctrlobj.onmouseover : null;
        ctrlobj.onmouseover = function(e) {
            doane(e);
            if (this.overfunc) this.overfunc();
            if (click) {
                clearTimeout(jsmenu['timer'][this.id]);
                jsmenu['timer'][this.id] = null;
            } else {
                for (var id in jsmenu['timer']) {
                    if (jsmenu['timer'][id]) {
                        clearTimeout(jsmenu['timer'][id]);
                        jsmenu['timer'][id] = null;
                    }
                }
            }
        }
    }
}

function initMenu(ctrlid, menuobj, duration, timeout, layer, drag) {
    if (menuobj && !menuobj.initialized) {
        menuobj.initialized = true;
        menuobj.ctrlkey = ctrlid;
        menuobj.onclick = ebygum;
        menuobj.style.position = 'absolute';
        if (duration < 3) {
            if (duration > 1) {
                menuobj.onmouseover = function() {
                    clearTimeout(jsmenu['timer'][ctrlid]);
                    jsmenu['timer'][ctrlid] = null;
                }
            }
            if (duration != 1) {
                menuobj.onmouseout = function() {
                    jsmenu['timer'][ctrlid] = setTimeout('hideMenu(' + layer + ')', timeout);
                }
            }
        }
        menuobj.style.zIndex = 999 + layer;
        if (ctrlid.indexOf("calendarexp") != -1)
            menuobj.style.zIndex = 10003;
        if (drag) {
            menuobj.onmousedown = function(event) { try { menudrag(menuobj, event, 1); } catch (e) { } };
            menuobj.onmousemove = function(event) { try { menudrag(menuobj, event, 2); } catch (e) { } };
            menuobj.onmouseup = function(event) { try { menudrag(menuobj, event, 3); } catch (e) { } };
        }
    }
}

function showMenu(ctrlid, click, offset, duration, timeout, layer, showid, maxh, drag) {
    var ctrlobj = $(ctrlid);
    if (!ctrlobj) return;
    if (isUndefined(click)) click = false;
    if (isUndefined(offset)) offset = 0;
    if (isUndefined(duration)) duration = 2;
    if (isUndefined(timeout)) timeout = 250;
    if (isUndefined(layer)) layer = 0;
    if (isUndefined(showid)) showid = ctrlid;
    var showobj = $(showid);
    var menuobj = $(showid + '_menu');
    if (!showobj || !menuobj) return;
    if (isUndefined(maxh)) maxh = 400;
    if (isUndefined(drag)) drag = false;

    if (click && jsmenu['active'][layer] == menuobj) {
        hideMenu(layer);
        return;
    } else {
        hideMenu(layer);
    }

    var len = jsmenu['timer'].length;
    if (len > 0) {
        for (var i = 0; i < len; i++) {
            if (jsmenu['timer'][i]) clearTimeout(jsmenu['timer'][i]);
        }
    }

    initCtrl(ctrlobj, click, duration, timeout, layer);
    ctrlobjclassName = ctrlobj.className;
    ctrlobj.className += ' hover';
    initMenu(ctrlid, menuobj, duration, timeout, layer, drag);

    menuobj.style.display = '';
    if (!is_opera) {
        menuobj.style.clip = 'rect(auto, auto, auto, auto)';
    }

    setMenuPosition(showid, offset);

    if (maxh && menuobj.scrollHeight > maxh) {
        menuobj.style.height = maxh + 'px';
        if (is_opera) {
            menuobj.style.overflow = 'auto';
        } else {
            menuobj.style.overflowY = 'auto';
        }
    }

    if (!duration) {
        setTimeout('hideMenu(' + layer + ')', timeout);
    }

    jsmenu['active'][layer] = menuobj;
}

function setMenuPosition(showid, offset) {
    var showobj = $(showid);
    var menuobj = $(showid + '_menu');
    if (isUndefined(offset)) offset = 0;
    if (showobj) {
        showobj.pos = fetchOffset(showobj);
        showobj.X = showobj.pos['left'];
        showobj.Y = showobj.pos['top'];
        if ($(InFloat) != null) {
            var InFloate = InFloat.split('_');
            if (!floatwinhandle[InFloate[1] + '_1']) {
                floatwinnojspos = fetchOffset($('floatwinnojs'));
                floatwinhandle[InFloate[1] + '_1'] = floatwinnojspos['left'];
                floatwinhandle[InFloate[1] + '_2'] = floatwinnojspos['top'];
            }
            showobj.X = showobj.X - $(InFloat).scrollLeft - parseInt(floatwinhandle[InFloate[1] + '_1']);
            showobj.Y = showobj.Y - $(InFloat).scrollTop - parseInt(floatwinhandle[InFloate[1] + '_2']);
            InFloat = '';
        }
        showobj.w = showobj.offsetWidth;
        showobj.h = showobj.offsetHeight;
        menuobj.w = menuobj.offsetWidth;
        menuobj.h = menuobj.offsetHeight;
        if (offset < 3) {
            menuobj.style.left = (showobj.X + menuobj.w > document.body.clientWidth) && (showobj.X + showobj.w - menuobj.w >= 0) ? showobj.X + showobj.w - menuobj.w + 'px' : showobj.X + 'px';
            menuobj.style.top = offset == 1 ? showobj.Y + 'px' : (offset == 2 || ((showobj.Y + showobj.h + menuobj.h > document.documentElement.scrollTop + document.documentElement.clientHeight) && (showobj.Y - menuobj.h >= 0)) ? (showobj.Y - menuobj.h) + 'px' : showobj.Y + showobj.h + 'px');
        } else if (offset == 3) {
            menuobj.style.left = (document.body.clientWidth - menuobj.clientWidth) / 2 + document.body.scrollLeft + 'px';
            menuobj.style.top = (document.body.clientHeight - menuobj.clientHeight) / 2 + document.body.scrollTop + 'px';
        }

        if (menuobj.style.clip && !is_opera) {
            menuobj.style.clip = 'rect(auto, auto, auto, auto)';
        }
    }
}

function hideMenu(layer) {
    if (isUndefined(layer)) layer = 0;
    if (jsmenu['active'][layer]) {
        try {
            $(jsmenu['active'][layer].ctrlkey).className = ctrlobjclassName;
        } catch (e) { }
        clearTimeout(jsmenu['timer'][jsmenu['active'][layer].ctrlkey]);
        jsmenu['active'][layer].style.display = 'none';
        if (is_ie && is_ie < 7 && jsmenu['iframe'][layer]) {
            jsmenu['iframe'][layer].style.display = 'none';
        }
        jsmenu['active'][layer] = null;
    }
}


function fetchOffset(obj) {
    var left_offset = obj.offsetLeft;
    var top_offset = obj.offsetTop;
    while ((obj = obj.offsetParent) != null) {
        left_offset += obj.offsetLeft;
        top_offset += obj.offsetTop;
    }
    return { 'left': left_offset, 'top': top_offset };
}

function ebygum(eventobj) {
    if (!eventobj || is_ie) {
        window.event.cancelBubble = true;
        return window.event;
    } else {
        if (eventobj.target.type == 'submit') {
            eventobj.target.form.submit();
        }
        eventobj.stopPropagation();
        return eventobj;
    }
}
//-------------------------------------------------------------/浮动展示--------------------------------------------------------------------

function writeCookie(name, value, hours) {
    var expire = "";
    if (hours != null) {
        expire = new Date((new Date()).getTime() + hours * 3600000);
        expire = "; expires=" + expire.toGMTString();
    }
    document.cookie = name + "=" + escape(value) + expire;
}


function readCookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}
function clearNoNumPage(obj) {
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d.]/g, "");
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g, "");
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g, ".");
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    if (obj.value == '') {
        obj.value = 1;
    }
    if (obj.value == 0) {
        obj.value = 1;
    }
}
function clearNoNum(obj) {
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d.]/g, "");
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g, "");
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g, ".");
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    if (obj.value == '') {
        obj.value = 0;
    }
}

function clearNoNumMino(obj) {
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d.]/g, "");
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g, "");
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g, ".");
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
}